﻿
using System.IO;

using System.Xml;

namespace SKN
{
    /// <summary>
    /// 
    /// </summary>
    public static class Configurator
    {

        ///<summary>
        ///</summary>
        ///<param name="filePath"></param>
        ///<param name="nodeName"></param>
        public static void LoadConfiguration(string filePath,string nodeName)
        {
              if (!File.Exists(filePath) )
            {
                return;
            }

            var doc = new XmlDocument();
            
            try
            {
                doc.Load(filePath);
            }
            catch (XmlException)
            {
                return;
            }

            XmlNode xWebProperties = doc.DocumentElement.SelectSingleNode(nodeName);
            
            if (xWebProperties == null)
            {
                return;
            }

            foreach (XmlNode xWebProperty in xWebProperties.ChildNodes)
            {
                if (xWebProperty.Attributes["Key"] != null && xWebProperty.Attributes["Value"] != null)
                {
                    string key = xWebProperty.Attributes["Key"].Value;
                    string value = xWebProperty.Attributes["Value"].Value;
                    
                    //if (web.Properties.ContainsKey(key))
                    //{
                    //    web.Properties[key] = value;
                    //}
                    //else
                    //{
                    //    web.Properties.Add(key, value);
                    //}
                }
            }

            //web.Properties.Update();
        }
        

    }
}
